//
//  MacAddressManager.m
//  DevSpoof
//
//  Created by huang on 2018/11/7.
//  Copyright © 2018年 wdys. All rights reserved.
//

#import "MacAddressManager.h"
#import "CommandLine.h"
@implementation MacAddressManager
+ (instancetype)shared{
    static id _instance = nil;
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        _instance = [[self class] new];
    });
    return _instance;
}
- (MacAddressInfo *)currentMacAddress{
    return [MacAddressInfo generateCurrent];
}
- (void)changeMacAddress:(void(^)(MacAddressInfo*target, MacAddressInfo*result))handler{
    MacAddressInfo *info = [MacAddressInfo generateNew];
    dispatch_async(dispatch_get_global_queue(0, 0), ^{
        NSString *filepath = [[NSBundle mainBundle] pathForResource:@"MacAddressSpoof" ofType:@"sh"];
        [CommandLine command:filepath argvs:@[@"1",info.wifiMac]];
        [CommandLine command:filepath argvs:@[@"0",info.ethernetMac]];
        MacAddressInfo *current = [MacAddressInfo generateCurrent];
        dispatch_sync(dispatch_get_main_queue(), ^{
            handler(info,current);
        });
    });
}
@end
